﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeetCode100Hot.笔试.掌趣科技
{
    public class ListNodeZQ
    {
        public int val;

        public ListNodeZQ next;

        public ListNodeZQ(int val = 0, ListNodeZQ next = null)
        {
            this.val = val;
            this.next = next;
        }

    }
    public class StackZQ
    {



        private ListNodeZQ preTop;

        private int _Count;//
        public int Count
        {
            get { return _Count; }
            set { _Count = value; }


        }
        public StackZQ() {
            preTop=new ListNodeZQ();

            _Count = 0;
        }
        public int Pop()
        {
            if(_Count > 0)
            {
                int val = preTop.val;
                preTop = preTop.next;
                _Count--;
                return val;
            }else { throw new InvalidOperationException("栈为空"); }
           
        } 
        public int Peek()
        {

            return preTop.val;
        }  
        public void Push(int newVal)
        {
            ListNodeZQ newNode = new ListNodeZQ(newVal,preTop);
            preTop = newNode;

            _Count++;
        }





    }






    internal class 单链表实现栈
    {
        static void Main掌趣科技单链表实现栈(string[] args)
        {

            StackZQ stackZQ = new StackZQ();

            for (int i = 0; i <10; i++)
            {
                stackZQ.Push(i);
                Console.WriteLine("stackZQ.Count:   "+stackZQ.Count);
            }
            Console.WriteLine("stackZQ.peek" + stackZQ.Peek());
            while (stackZQ.Count > 0)
            {
                Console.WriteLine("Pop():    " + stackZQ.Pop());
                Console.WriteLine("stackZQ.Count:   " + stackZQ.Count);
            };


        }
    }
}
